package com.siwei.eqi.controller;

import com.siwei.eqi.pojo.ResultBean;
import com.siwei.eqi.pojo.vo.BatchResultVO;
import com.siwei.eqi.pojo.vo.DeliveryTaskBatchVO;
import com.siwei.eqi.service.IDeliveryTaskBatchResultService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 汇交结果表 前端控制器
 * </p>
 *
 * @author hzl
 * @since 2025-04-02
 */
@RestController
@RequestMapping("/deliveryTaskBatchResult")
public class DeliveryTaskBatchResultController {

    @Autowired
    private IDeliveryTaskBatchResultService resultService;

    @PostMapping("/import")
    @ApiOperation(value = "上传汇交结果文件")
    public ResultBean importDeliveryResult(@ApiParam(value = "上传的文件", required = true) @RequestPart("file") MultipartFile file) {
        boolean b = false;
        try {
            b = resultService.importFile(file);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (b) {
            return ResultBean.success();
        } else {
            return ResultBean.failed();
        }
    }

    /**
     * 汇交结果-列表查询
     * @param batchId
     * @return
     */
    @GetMapping("/list")
    public ResultBean<List<BatchResultVO>> queryList(@RequestParam(required = true,value = "批次列表id") String batchId) {
        return ResultBean.success(resultService.queryList(batchId));
    }

}
